//
//  SINAStudentAskLeaveTypeSelectView.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/22.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAStudentAskLeaveTypeSelectView.h"



static float viewShowDuration = 0.2;
static float viewHidDuration = 0.2;
static int viewHeight = 200;


@implementation SINAStudentAskLeaveTypeSelectView

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */





- (instancetype)init{
    
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup{
    
    //弹出菜单，添加半透明背景
    _backView = [UIButton buttonWithType:UIButtonTypeCustom];
    _backView.frame = CGRectMake(0, 0, mainW, mainH);
    _backView.alpha = 0.3;
    _backView.backgroundColor = [UIColor blackColor];
    [_backView addTarget:self action:@selector(backViewClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    self.frame = CGRectMake(0, mainH, mainW, viewHeight);
    self.backgroundColor = [UIColor whiteColor];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 100, mainW-20, 200)];
    [view setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:view];
    
}

- (void)backViewClicked:(id)sender{
    [self hide];
}

- (void)show{
    
    [[[UIApplication sharedApplication] keyWindow] addSubview:_backView];
    [[[UIApplication sharedApplication] keyWindow] insertSubview:self aboveSubview:_backView];
    
    [UIView animateWithDuration:viewShowDuration animations:^{
        
        self.frame = CGRectMake(0, mainH - viewHeight, mainW, viewHeight);
        
    } completion:^(BOOL finished) {
        
    }];
    
}

- (void)hide{
    
    [_backView removeFromSuperview];
    
    [UIView animateWithDuration:viewHidDuration animations:^{
        
        self.frame = CGRectMake(0, mainH, mainW , viewHeight);
        
    } completion:^(BOOL finished) {
        
    }];
    
    
}

- (void)share:(id)sender{
    UIButton *button = (UIButton *)sender;
    if (self.shareButtonClickBlock) {
        self.shareButtonClickBlock(button.tag);
    }
}

@end
